// 导入用户集合
const { Goods } = require('../../../model/goods');
const moment = require('moment')
const { decodeToken } = require('../../../middleGuard/jwt.js')

module.exports = async (req, res) => {
    console.log(req.headers.authorization)
    console.log('req.tokenInfo', req.tokenInfo)
    const userId = decodeToken(req.headers.authorization).userId
  Goods.create({ ...req.body, user: userId, createTime: moment().format('YYYY-MM-DD HH:mm:ss') }).then(item => {
    res.json({
        data: item,
        message: '添加成功！'
    })
  }).catch((err) => {
    res.status(403)
    res.json({
        log: err,
        message: '添加失败！'
    })
  })
}